package cn.com.lms.business.examRewrite.persistence.repository;


import cn.com.lms.business.examRewrite.persistence.entity.ExerciseEmployeeReWriteVo;
import com.bnzj.core.persistence.repository.BaseRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ExerciseEmployeeReWriteVoDao extends BaseRepository<ExerciseEmployeeReWriteVo,Long> {
    @Query(nativeQuery = true,value = "SELECT * FROM bnz_sys_user su JOIN (SELECT * FROM bnz_exam_exercise_employee WHERE exercise_id = ?1) as eee WHERE su.id = eee.employee_id")
    List<ExerciseEmployeeReWriteVo> getEmployeeById(Long id);


    @Query(nativeQuery = true,value = "SELECT * FROM bnz_exam_exercise_employee WHERE exercise_id=?1")
    List<ExerciseEmployeeReWriteVo> getDataById(Long id);


    /**
     * 通过exercise_id获取employeeId
     * @param id
     * @return
     */
    @Query(nativeQuery = true,value = "SELECT employee_id FROM bnz_exam_exercise_employee WHERE exercise_id = ?1")
    List<Long> getEmployeexByExerciseId(Long id);

    /**
     * 通过exercise_id删除
     * @param result
     * @param id
     */
    @Query(nativeQuery = true,value = "UPDATE bnz_exam_exercise_employee SET is_delete = :result WHERE exercise_id in (:id)")
    @Modifying
    void deleteSByExerciseId(@Param("result") boolean result, @Param("id") List<Long> id);
}
